package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.query.SearchQueryObject;
import cn.wolfcode.trip.base.service.IDailyService;
import cn.wolfcode.trip.base.service.ISearchService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.service.ITravelService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SearchServiceImpl implements ISearchService {
    //攻略
    @Autowired
    private IStrategyService strategyService;
    //游记
    @Autowired
    private ITravelService travelService;
    //日报
    @Autowired
    private IDailyService dailyService;

    @Override
    public Map queryForCount(SearchQueryObject qo) {
        HashMap<Object, Object> map = new HashMap<>();
        int strategyCount = strategyService.queryForCount(qo);
        int travelCount = travelService.queryForCount(qo);
        int dailyCount = dailyService.queryForCount(qo);
        map.put("strategyCount", strategyCount);
        map.put("travelCount", travelCount);
        map.put("dailyCount", dailyCount);
        map.put("count", dailyCount + strategyCount + travelCount);
        return map;
    }

    @Override
    public PageInfo<Object> queryTypeForList(SearchQueryObject qo) {
        if (qo.getType() == 1) {
            return strategyService.queryForList(qo);
        } else if (qo.getType() == 2) {
            return travelService.query(qo);
        } else {
            return dailyService.query(qo);
        }
    }

    @Override
    public PageInfo selectAll(SearchQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize(), true, false, null);
        List list = new ArrayList();
        Map map = new HashMap<>();
        PageInfo<Object> strategy = strategyService.queryForList(qo);
        PageInfo travel = travelService.query(qo);
        PageInfo daily = dailyService.query(qo);
        map.put("strategy", strategy);
        map.put("travel", travel);
        map.put("daily", daily);
        list.add(map);
        return new PageInfo<>(list);
    }
}
